function[duality_gap rel_duality_gap] = compute_duality_gap(model, data, errors, sig, primal_cost)
 

dual_candidate = min(1, model.lambda/sig) * 2 * errors;
fenchel_dual =  (dual_candidate'*dual_candidate)/4 + (dual_candidate'*data.entries);
dual_cost = -fenchel_dual;

duality_gap = primal_cost - dual_cost;
rel_duality_gap = duality_gap/abs(dual_cost);  